package com.ithema.b2b.goodsconsumer.filter;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class MyLoginFilter extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler) throws Exception {
        System.out.println("我是拦截器：我证明我曾活在这个世界上！");
        String userInfo = (String)request.getSession().getAttribute("uaccount");

        if (userInfo == null || userInfo.isEmpty()) {
            System.out.println("用户暂未登录！");
            response.sendRedirect(request.getContextPath() + "redirect:/admin/tologin");
            return false;
        }

        System.out.println("用户已登录！");
        return true;
    }

}
